<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<!--<![endif]-->
<!-- BEGIN HEAD -->
<!-- BEGIN BODY -->
<body class="page-header-fixed">
<!-- BEGIN PAGE CONTENT-->
<div class="site_content">
    <div class="realtime_content content_box no_table_filter">
        <div>
            <form class="instruct_box" id="form_id" method="post">
                <hr />
                <div style="width: 400px">
                    <div class="form-group form1">
                        <label>设备地址</label>
                        <input type="text" class="form-control" id="chargerId" name="chargerId" placeholder="请输入设备地址">
                        <span id="chargerInner"></span>
                    </div>
                    <!--<div class="form-group form1">-->
                        <!--<label>设备类型</label> <input type="text" class="form-control" id="chargerType" name="chargerType" placeholder="请输入chargerType">-->
                    <!--</div>-->
                    <div class="form-group form1">
                        <label>用户卡号</label> <input type="text" class="form-control" id="userCard" name="userCard" placeholder="请输入用户卡号">
                    	<span id="userInner"></span>
                    </div>
                    <div class="form-group form1">
                        <label>端口号</label>
                        <input class="form-control" id="portNo" name="portNo" placeholder="请输入portNo，从1开始">
                    	<span id="portNoInner"></span>
                    </div>
                    <!--<div class="form-group form1">-->
                        <!--<label for="">encryption</label>-->
                        <!--<input class="form-control" type="text" id="encryption" name="encryption" placeholder="请输入encryption"/>-->
                    <!--</div>-->
                    <!--<div class="form-group form1">-->
                        <!--<label for="">bespeakMinute</label>-->
                        <!--<input class="form-control" type="text" id="bespeakMinute" name="bespeakMinute" placeholder="请输入bespeakMinute"/>-->
                    <!--</div>-->
                    <!--<div class="form-group form1">-->
                        <!--<label for="">bespeakStartSerialNumber</label>-->
                        <!--<input class="form-control" type="text" id="bespeakStartSerialNumber" name="bespeakStartSerialNumber" placeholder="请输入bespeakStartSerialNumber"/>-->
                    <!--</div>-->
                </div>
                <div class="modal-footer t_l">
                    <button style="margin-bottom:0px" type="reset" class="btn btn-warning" data-dismiss="modal">
                        <i class="fa fa-refresh"></i> 重置
                    </button>
                    <!--<button type="button" class="btn btn-danger">-->
                        <!--<i class="fa fa-times-circle"></i> 取消预约-->
                    <!--</button>-->
                    <button type="button" class="btn btn-primary">
                        <i class="fa fa-user"></i> 开始预约
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>
<!-- END PAGE CONTENT-->
</body>
<script>
var charger = $('#chargerId');
var user = $('#userCard');
var port = $('#portNo');
$('#chargerId').on('blur',function(){
	var chargerId = $('#chargerId').val();
	if(/^\d{16}$/.test(chargerId)){
		$('#chargerInner').html('');
        charger.isError = false;
	}else{
		$('#chargerInner').html('设备地址必须为16位数字').css('color','red');
         charger.isError = true;	
		
	}
	
});
$('#userCard').on('blur',function(){
	var userCard = $('#userCard').val();
	if(/^\d{20}$/.test(userCard)){
		$('#userInner').html('');
        user.isError = false;
	}else{
		$('#userInner').html('用户卡号必须为20位数字').css('color','red');
         user.isError = true;
	}
});
$('#portNo').on('blur',function(){
	var portNo = $('#portNo').val();
	if(!/^\d{1}$/.test(portNo)){
		$('#portNoInner').html('端口号只能为1位数字').css('color','red');
         port.isError = true;
	}else{
		$('#portNoInner').html('');
        port.isError = false;
	}
});
    $('button.btn-primary').on('click',function(){
        if(user.isError==false && port.isError==false && charger.isError==false){
            $.ajax({
            type:'post',
            url:'/cms/bespeak',
            data:$('#form_id').serialize(),
            dataType: "json",
            async: false,
            success:function(data){
                if(data.code == '200'){
                    bootboxWindow.alert("指令下发成功!", null);
                }else{
                    bootboxWindow.alert("指令下发失败!", null);
                    $('#account').val('');
                    $('#password').val('');
                }
            },
            error: function(){
                bootboxWindow.alert("指令下发失败!", null);
            }

        })
        }else{
            $('#userInner').html('用户卡号必须为20位数字').css('color','red');
            $('#chargerInner').html('设备地址必须为16位数字').css('color','red');
            $('#portNoInner').html('端口号只能为1位数字').css('color','red');
        }
    });
</script>
</html>
